<?php
require_once 'file_helper.php';
function load_view($view_name, $vars_array = array()) {
    $views_path = APPPATH . 'views/';
    $view_path = path_join($views_path, "$view_name.php");
    if (!file_exists($view_path)) {
        show_error('Unable to load the requested file: ' . $view_path);
    }
    if (!is_array($vars_array)) {
        show_error('You must pass a array as view variables');
    }
    extract($vars_array);
    ob_start();
    if ((bool)@ini_get('short_open_tag') === FALSE AND config_item('rewrite_short_tags') == TRUE) {
        echo eval('?>' . preg_replace("/;*\s*\?>/", "; ?>", str_replace('<?=', '<?php echo ', file_get_contents($view_path))));
    } else {
        include ($view_path);
        // include() vs include_once() allows for multiple views with the same name
    }
    // Return the file data if requested
    ob_end_flush();
}
function load_model($model_name) {
    $models_path = APPPATH . 'models/';
    $model_path = path_join($models_path, "$model_name.php");
    if (!file_exists($model_path)) {
        show_error('Unable to load the requested file: ' . $model_path);
    }
    include ($model_path);
    return new $model_name();
}
function show_error($msg) {
    echo($msg);
    exit();
}
